// StringTools.h
//
#ifndef STRINGTOOLS_ONCE
#define STRINGTOOLS_ONCE

#include <string>
#include <vector>


// ------------------------------------------------------------------------------------------------
inline std::vector<std::string> split( const std::string &str, const std::string &delimiters )
{
	std::vector<std::string> out;

	std::size_t start = 0;
	std::size_t pos   = str.find_first_of( delimiters, start );
	
	while( pos != std::string::npos )
	{
		if( pos != start )
			out.push_back( str.substr(start,pos-start) );
		
		start = pos+1;
		pos=str.find_first_of(delimiters,start);
	}
	
	if( start<str.length() )
		out.push_back( str.substr(start) );

	return out;
}

// ------------------------------------------------------------------------------------------------
inline bool startsWith( const std::string &str, const std::string &key )
{
	const std::string left = str.substr( 0,key.size() );

	return left == key;
}

// ------------------------------------------------------------------------------------------------
inline bool endsWith( const std::string &str, const std::string &key )
{
	if( str.size() < key.size() )
		return false;

	const std::string right = str.substr( str.size()-key.size(),key.size() );

	return right == key;
}

// ------------------------------------------------------------------------------------------------
inline std::string after( const std::string &str, const std::string &delimiter )
{
	const size_t pos = str.find_first_of( delimiter )+1;

	std::string ret = str.substr( pos, std::string::npos );

	return ret;
}

#endif